#include "glHelper.hpp"
#include "creature.hpp"
#include "consumable.hpp"

using namespace std;

extern float angle;

void drawSquare(int side) {
    side/=2;
    //Draw
    glPushMatrix();
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_QUADS);
    glVertex2i(-side, -side); // The bottom left corner
    glVertex2i(-side, side); // The top left corner
    glVertex2i(side, side); // The top right corner
    glVertex2i(side, -side); // The bottom right corner
    glEnd();
    glPopMatrix();
}

void drawTeapot(float angle, float state) {
    //Rotate teapot
    glPushMatrix();
    glScalef(100.0f, 100.0f, 1.0f);
    glTranslatef(sin(angle),
                 cos(angle), 0.0f);
    glColor3f(1.0f, 0.0f, 0.0f);

    glScalef(1.0f, state, 1.0f);
    glutSolidTeapot(0.5f);
    glPopMatrix();
}

void drawCrap() {
    glPushMatrix();
    glTranslatef(320.0f, 240.0f, 0.0f);
    drawSquare(400);
    drawTeapot(angle, 1.0f);
    drawTeapot(angle + 120.0f*DEG_TO_RAD, 1.0f);
    drawTeapot(angle + 240.0f*DEG_TO_RAD, 1.0f);
    drawTeapot(-angle, -1.0f);
    drawTeapot(-angle + 120.0f*DEG_TO_RAD, -1.0f);
    drawTeapot(-angle + 240.0f*DEG_TO_RAD, -1.0f);
    glPopMatrix();
}

void drawCircle(float rad) {
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(0.0f, 0.0f);
    for(float i=0.0f; i<2*PI; i+=0.25f) {  //Change increment to lower for better looking circle
        glVertex2f(rad*cos(i), rad*sin(i));
    }
    glVertex2f(rad, 0.0f);
    glEnd();
}

void normalize(s_vector &v) {
    v.x /= absVector(v);
    v.y /= absVector(v);
}

